﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class FormRelationMapFilter : Form
    {
        public FormRelationMapFilter()
        {
            InitializeComponent();

            this.checkedListBox1.CheckOnClick = true;
        }

        public Dictionary<string, bool> AllTables { get; internal set; }

        private void FormRelationMapFilter_Load(object sender, EventArgs e)
        {
            int index = 0;
            var allKeys = AllTables.Keys.ToList();
            allKeys.Sort();
            foreach (var table in allKeys)
            {
                this.checkedListBox1.Items.Add(table);
                this.checkedListBox1.SetItemChecked(index, AllTables[table]);
                index++;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (var i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                var key = this.checkedListBox1.Items[i];
                AllTables[key.ToString()] = this.checkedListBox1.GetItemChecked(i);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for(var i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                this.checkedListBox1.SetItemChecked(i,true);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            for (var i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                this.checkedListBox1.SetItemChecked(i, false);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            for (var i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                var t=this.checkedListBox1.GetItemChecked(i);
                this.checkedListBox1.SetItemChecked(i, !t);
            }
        }
    }
}
